import pymysql


def save_myaql(sql,val,**dbinfo):
    try:
        connect = pymysql.connect(**dbinfo)
        cursor = connect.cursor()
        cursor.executemany(sql, val)
        connect.commit()
    except Exception as e:
        connect.rollback()
        print(e)
    finally:
        cursor.close()
        connect.close()




if __name__ == '__main__':

    sql = "insert into teacherinfo(tno,tname,remark) values(%s,%s,%s)"
    val = [['1300434', '刘佳慧', '非常好看'], ['1300433', 'adou', '不镇魔好看']]
    data = {'host': '127.0.0.1',
            'user': 'root',
            'password': 'root',
            'db': 'spider',
            'charset': 'utf8',
            'cursorclass': pymysql.cursors.DictCursor}
    save_myaql(sql, val, **data)
